package ca.tatham.senssim.diffusion;

import ca.tatham.senssim.Simulation;
import ca.tatham.senssim.util.Address;

class Gradient
{
  private final int m_interval;
  private final int m_duration;
  private final int m_startTime;
  private final Address m_address;

  private int m_lastSent = 0;

  public Gradient(Address address, int interval, int duration, int startTime)
  {
    m_address = address;
    m_interval = interval;
    m_duration = duration;
    m_startTime = startTime;
  }

  public boolean shouldSend()
  {
    if (m_lastSent == 0 || Simulation.getTime() >= m_interval + m_lastSent)
    {
      m_lastSent = Simulation.getTime();
      return true;
    }
    return false;
  }

  public boolean isExpired()
  {
    return Simulation.getTime() >= m_duration + m_startTime;
  }

  public Address getAddress()
  {
    return m_address;
  }

  public int getDuration()
  {
    return m_duration;
  }

  public int getInterval()
  {
    return m_interval;
  }

  public int getStartTime()
  {
    return m_startTime;
  }

  @Override
  public String toString()
  {
    return "Gradient to: " + getAddress() + " for " + getDuration() + "@"
        + getInterval();
  }

}